package org.bilinc.gz001.dao;


import org.bilinc.gz001.dao.interfaces.AbstractDaoImpl;
import org.bilinc.gz001.dao.interfaces.IGazConstantDao;
import org.bilinc.gz001.entity.GazConstant;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

@Component
public class GazConstantDao extends AbstractDaoImpl<GazConstant> implements IGazConstantDao {

    GazConstantDao() {
    }

    public GazConstant findByName(String name) {
        GazConstant gazConstant =  (GazConstant) getSession().createCriteria(GazConstant.class).add(Restrictions.eq("name", name)).uniqueResult();
        closeSession();
        return gazConstant;
    }

    public Integer getGNV() {
        return Integer.valueOf(findByName("GNV").getValue());
    }

    public Double getNO() {
        return Double.parseDouble(findByName("NO").getValue());
    }

    public void setGNV(Integer GNV) {
        GazConstant gazConstant =  (GazConstant) createCriteriaInTransaction().add(Restrictions.eq("name", "GNV")).uniqueResult();
        gazConstant.setValue(String.valueOf(GNV));
        commitTransaction();
    }

    public void setNO(Double NO) {
        GazConstant gazConstant =  (GazConstant) createCriteriaInTransaction().add(Restrictions.eq("name", "GNV")).uniqueResult();
        gazConstant.setValue(String.valueOf(NO));
        commitTransaction();
    }
}
